<template>
  <dialog-editor ref="dialog"></dialog-editor>
</template>

<script>
import DialogEditor from '@/components/DialogEditor'
import dialogMixins from '@/utils/commonDialogMixins'

export default {
  mixins: [dialogMixins],
  components: {DialogEditor},
  data() {
    return {
      visible: false,
      dataFormConfig: {
        id: {
          hidden: true
        },
        partInfoId: {
          label: '配件',
          type: 'list',
          placeholder: '请选择配件',
          list: [],
          isNeedAdd: true,
          addNewItemFunc: this.addNewPart
        },
        partNumber: {
          label: '入库数量',
          type: 'number',
          max: 100000000,
          default: 0
        },
        dayTime: {
          label: '日期',
          type: 'date',
          placeholder: '请选择日期'
        },
        imageUrl: {
          label: '入库单留存',
          type: 'uploadImage',
          imageType: 'uploadPartImage'
        },
        personName: {
          label: '人员',
          placeholder: '请输入人员'
        },
        status: {
          label: '状态',
          type: 'switch',
          activeValue: 1,
          inactiveValue: 0,
          default: 1
        }
      }
    }
  },
  methods: {
    addNewPart() {
      const cb = (newValue) => {
        this.initPartInfoList()
        this.dataForm.partInfoId = newValue.id
      }
      this.$parent.openPartInfoDialog(cb)
    },
    init(id) {
      this.dataForm.id = id || 0
      this.initPartInfoList()

      this.$refs.dialog.initDialog({
        dataForm: this.dataForm,
        config: this.dataFormConfig,
        dataRule: this.getNeedDataRule('partInfoId', 'partNumber', 'personName', 'dayTime'),
        initApi: 'partApi/partAddInfo',
        saveApi: 'partApi/savePartAdd',
        updateApi: 'partApi/updatePartAdd',
        objectName: 'partAdd'
      })
    }
  }
}
</script>
